/*************************************************************************
	> File Name: state.h
	> Author: ma6174
	> Mail: ma6174@163.com 
	> Created Time: 2021年12月01日 星期三 20时26分52秒
 ************************************************************************/

#include<iostream>
#include <string>

class State;

class Work
{
public:
	Work();
	Work(int h);

	void setHour(int h)
	{
		hour = h;
	}

	int getHour()
	{
		return hour;
	}

	void setFinish(bool b)
	{
		finish = b;
	}

	bool getFinish()
	{
		return finish;
	}

	void setState(State* s);
	void printProgram();


private:
	int hour;
	State* current;
	bool finish = false;
};


//状态模式
class State
{
public:
	virtual void printProgram(Work w) = 0;
};

class SleepingState : public State
{
public:
	virtual void printProgram(Work w)
	{
		std::cout << "当前时间: " << w.getHour() << "点，不行了，得睡觉了" << std::endl;
	}
};

class RestState : public State
{
public:
	virtual void printProgram(Work w)
	{
		std::cout << "当前时间: " << w.getHour() << "点，下班回家了" << std::endl;
	}
};

class EveningState : public State
{
public:
	virtual void printProgram(Work w)
	{
		if (w.getFinish())
		{
			w.setState(new RestState());
			w.printProgram();
		}
		else
		{
			if (w.getHour() < 21)
				std::cout << "当前时间: " << w.getHour() << "点，加班哦，疲惫至极" << std::endl;
			else
			{
				w.setState(new SleepingState());
				w.printProgram();
			}
		}
	}
};

class AfternoonState : public State
{
public:
	virtual void printProgram(Work w)
	{
		if (w.getHour() < 17)
			std::cout << "当前时间: " << w.getHour() << "点，下午状态还不错，继续努力" << std::endl;
		else
		{
			w.setState(new EveningState());
			w.printProgram();
		}
	}
};

class NoonState : public State
{
public:
	virtual void printProgram(Work w)
	{
		if (w.getHour() < 13)
			std::cout << "当前时间: " << w.getHour() << "点，饿了，午饭，犯困，午休" << std::endl;
		else
		{
			w.setState(new AfternoonState());
			w.printProgram();
		}
	}
};

class ForenoonState : public State
{
public:
	virtual void printProgram(Work w)
	{
		if (w.getHour() < 12)
			std::cout << "当前时间: " << w.getHour() << "点，上午工作，精神百倍" << std::endl;
		else
		{
			w.setState(new NoonState());
			w.printProgram();
		}
	}
};

//Work的实现
Work::Work()
{
	hour = 9;
	current = new ForenoonState();
	finish = false;
}

Work::Work(int h)
{
	hour = h;
	current = new ForenoonState();
	finish = false;
}

void Work::setState(State* s)
{
	current = s;
}

void Work::printProgram()
{
	current->printProgram(*this);
}
